<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');
?>

<p><a href="../">&lt;&lt; Back to Main Portal</a></p>
<h1>Instructors</h1>
<p><a href="add.php">Add Instructor</a></p>
<?php
//initalize variables used to connect to database
$db = "scheduler";
$user = "root";
$pass = "";

//counting variable
$i = 0;

//connect to database
mysql_connect("localhost", $user, $pass);
@mysql_select_db($db);

//select statement
$query = "SELECT * FROM instructors ORDER BY last_name";
$result = mysql_query($query);

//close
mysql_close();

//dynamically determine number of rows read from table
$num_rows = mysql_numrows($result);

echo '<p>';

if ($num_rows > 0)
{
		//start table
		echo "<table class=\"postSchedule\">";
			
			//create table rows with column IDs
			echo "<tr>";
				echo "<td><b>First Name</b></td>";
				echo "<td><b>Last Name</b></td>";
				echo "<td></td>";
				echo "<td></td>";
			echo "</tr>";
				
		//loop to walk through and print to screen all entries in buildings table
		$row_count = 0;
		while ($row = mysql_fetch_assoc($result)) 
		{
			$row_count++;
			//store each building name and abbreviation in a scalar
			$instructor_id=$row["id"];
			$instructor_fname=$row["first_name"];
			$instructor_lname=$row["last_name"];	
				
		//generate table row for each instructor on each iteration of the loop
		echo "<tr";
		if (($row_count%2) != 0) echo " class=\"zebra_stripe\"";
		echo ">";
			echo "<td>$instructor_fname</td>";		//instructor first name
			echo "<td>$instructor_lname</td>";		//instructor last name
			echo "<td>";		//cell containing form for edit instructor link/button
				echo "<a href='edit.php?id=$instructor_id'>Edit</a>";
			echo "</td>";
		
			echo "<td>";		//cell containing form for delete Instructor link/button
				echo "<a href='delete.php?id=$instructor_id'>Delete</a>";
			echo "</td>";
	
			echo "<td>";		//cell containing form for update availability link/button
				echo "<a href='update_availability.php?id=$instructor_id'>Update Availability</a>";
			echo "</td>";
			
			echo "<td>";		//cell containing form for update preference link/button
				echo "<a href='update_preferences.php?id=$instructor_id'>Update Preferences</a>";
			echo "</td>";
		
			echo "</tr>";
		
		//increment counting variable
		$i++;
	}
	//end table tag
	echo "</table>";

	echo '</p>';
}
else
{
	echo "<p><b>NO INSTRUCTORS CURRENTLY CURRENTLY IN TABLE</b></p>";
}

?>



<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>